<?php
/* tblSubCategory */
class tblSubCategory extends NocForm
	{
		protected $_ID                 = array();
		protected $_Category                 = array();
		protected $_SubCategory                 = array();
		protected $_SubCategoryDescription                 = array();
		protected $_DisplayOrder                 = array();
		protected $_UploadedPicture                 = array();
		protected $_MetaTitle                 = array();
		protected $_MetaDescription                 = array();
		protected $_MetaKeyword                 = array();
		protected $_MetaComment                 = array();

		function __construct()
		{
			parent::__construct();
			$this->getRow();
		}
		public function get_ID()
		{
				return  $this->_get_IDValue();
		}

		private function _get_IDValue()
		{
			if(isset($this->_ID['value']))
				return $this->_ID['value'];
			else
				return false;
		}

		public function get_Category()
		{
				return  $this->_get_CategoryValue();
		}

		private function _get_CategoryValue()
		{
			if(isset($this->_Category['value']))
				return $this->_Category['value'];
			else
				return false;
		}

		public function get_SubCategory()
		{
				return  $this->_get_SubCategoryValue();
		}

		private function _get_SubCategoryValue()
		{
			if(isset($this->_SubCategory['value']))
				return $this->_SubCategory['value'];
			else
				return false;
		}

		public function get_SubCategoryDescription()
		{
				return  $this->_get_SubCategoryDescriptionValue();
		}

		private function _get_SubCategoryDescriptionValue()
		{
			if(isset($this->_SubCategoryDescription['value']))
				return $this->_SubCategoryDescription['value'];
			else
				return false;
		}

		public function get_DisplayOrder()
		{
				return  $this->_get_DisplayOrderValue();
		}

		private function _get_DisplayOrderValue()
		{
			if(isset($this->_DisplayOrder['value']))
				return $this->_DisplayOrder['value'];
			else
				return false;
		}

		public function get_UploadedPicture()
		{
				return  $this->_get_UploadedPictureValue();
		}

		private function _get_UploadedPictureValue()
		{
			if(isset($this->_UploadedPicture['value']))
				return $this->_UploadedPicture['value'];
			else
				return false;
		}

		public function get_MetaTitle()
		{
				return  $this->_get_MetaTitleValue();
		}

		private function _get_MetaTitleValue()
		{
			if(isset($this->_MetaTitle['value']))
				return $this->_MetaTitle['value'];
			else
				return false;
		}

		public function get_MetaDescription()
		{
				return  $this->_get_MetaDescriptionValue();
		}

		private function _get_MetaDescriptionValue()
		{
			if(isset($this->_MetaDescription['value']))
				return $this->_MetaDescription['value'];
			else
				return false;
		}

		public function get_MetaKeyword()
		{
				return  $this->_get_MetaKeywordValue();
		}

		private function _get_MetaKeywordValue()
		{
			if(isset($this->_MetaKeyword['value']))
				return $this->_MetaKeyword['value'];
			else
				return false;
		}

		public function get_MetaComment()
		{
				return  $this->_get_MetaCommentValue();
		}

		private function _get_MetaCommentValue()
		{
			if(isset($this->_MetaComment['value']))
				return $this->_MetaComment['value'];
			else
				return false;
		}


		public function set_IDValue($strID)
		{
			if($this->validateInput("validatexxxxx", $strID, "ID "))
					return($this->_setNewValue($this->_ID, $strID));
			else
					return false;
		}

		public function set_CategoryValue($strCategory)
		{
			if($this->validateInput("validatexxxxx", $strCategory, "Category "))
					return($this->_setNewValue($this->_Category, $strCategory));
			else
					return false;
		}

		public function set_SubCategoryValue($strSubCategory)
		{
			if($this->validateInput("validatexxxxx", $strSubCategory, "SubCategory "))
					return($this->_setNewValue($this->_SubCategory, $strSubCategory));
			else
					return false;
		}

		public function set_SubCategoryDescriptionValue($strSubCategoryDescription)
		{
			if($this->validateInput("validatexxxxx", $strSubCategoryDescription, "SubCategoryDescription "))
					return($this->_setNewValue($this->_SubCategoryDescription, $strSubCategoryDescription));
			else
					return false;
		}

		public function set_DisplayOrderValue($strDisplayOrder)
		{
			if($this->validateInput("validatexxxxx", $strDisplayOrder, "DisplayOrder "))
					return($this->_setNewValue($this->_DisplayOrder, $strDisplayOrder));
			else
					return false;
		}

		public function set_UploadedPictureValue($strUploadedPicture)
		{
			if($this->validateInput("validatexxxxx", $strUploadedPicture, "UploadedPicture "))
					return($this->_setNewValue($this->_UploadedPicture, $strUploadedPicture));
			else
					return false;
		}

		public function set_MetaTitleValue($strMetaTitle)
		{
			if($this->validateInput("validatexxxxx", $strMetaTitle, "MetaTitle "))
					return($this->_setNewValue($this->_MetaTitle, $strMetaTitle));
			else
					return false;
		}

		public function set_MetaDescriptionValue($strMetaDescription)
		{
			if($this->validateInput("validatexxxxx", $strMetaDescription, "MetaDescription "))
					return($this->_setNewValue($this->_MetaDescription, $strMetaDescription));
			else
					return false;
		}

		public function set_MetaKeywordValue($strMetaKeyword)
		{
			if($this->validateInput("validatexxxxx", $strMetaKeyword, "MetaKeyword "))
					return($this->_setNewValue($this->_MetaKeyword, $strMetaKeyword));
			else
					return false;
		}

		public function set_MetaCommentValue($strMetaComment)
		{
			if($this->validateInput("validatexxxxx", $strMetaComment, "MetaComment "))
					return($this->_setNewValue($this->_MetaComment, $strMetaComment));
			else
					return false;
		}
		public function update()
		{
			if($this->_boFailedValidation)
					return false;
					$strErrorMsg = "";
					$strSuccessMsg = "";
			if($this->get_ID() == "")
					return $this->_setFailScreens("Update aborted no record selected.", true);

			$strJoin = "";
			$strSql = "UPDATE tblSubCategory
					SET ";
					if($this->_ID['updated'])
					{
						$strSql .= $strJoin." ID = '".$this->_ID['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_ID['oldvalue']."' to '".$this->_ID['value']."'<br/>";
						$strErrorMsg .= "ID not updated<br/>";					}

					if($this->_Category['updated'])
					{
						$strSql .= $strJoin." Category = '".$this->_Category['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Category['oldvalue']."' to '".$this->_Category['value']."'<br/>";
						$strErrorMsg .= "Category not updated<br/>";					}

					if($this->_SubCategory['updated'])
					{
						$strSql .= $strJoin." SubCategory = '".$this->_SubCategory['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_SubCategory['oldvalue']."' to '".$this->_SubCategory['value']."'<br/>";
						$strErrorMsg .= "SubCategory not updated<br/>";					}

					if($this->_SubCategoryDescription['updated'])
					{
						$strSql .= $strJoin." SubCategoryDescription = '".$this->_SubCategoryDescription['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_SubCategoryDescription['oldvalue']."' to '".$this->_SubCategoryDescription['value']."'<br/>";
						$strErrorMsg .= "SubCategoryDescription not updated<br/>";					}

					if($this->_DisplayOrder['updated'])
					{
						$strSql .= $strJoin." DisplayOrder = '".$this->_DisplayOrder['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_DisplayOrder['oldvalue']."' to '".$this->_DisplayOrder['value']."'<br/>";
						$strErrorMsg .= "DisplayOrder not updated<br/>";					}

					if($this->_UploadedPicture['updated'])
					{
						$strSql .= $strJoin." UploadedPicture = '".$this->_UploadedPicture['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_UploadedPicture['oldvalue']."' to '".$this->_UploadedPicture['value']."'<br/>";
						$strErrorMsg .= "UploadedPicture not updated<br/>";					}

					if($this->_MetaTitle['updated'])
					{
						$strSql .= $strJoin." MetaTitle = '".$this->_MetaTitle['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_MetaTitle['oldvalue']."' to '".$this->_MetaTitle['value']."'<br/>";
						$strErrorMsg .= "MetaTitle not updated<br/>";					}

					if($this->_MetaDescription['updated'])
					{
						$strSql .= $strJoin." MetaDescription = '".$this->_MetaDescription['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_MetaDescription['oldvalue']."' to '".$this->_MetaDescription['value']."'<br/>";
						$strErrorMsg .= "MetaDescription not updated<br/>";					}

					if($this->_MetaKeyword['updated'])
					{
						$strSql .= $strJoin." MetaKeyword = '".$this->_MetaKeyword['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_MetaKeyword['oldvalue']."' to '".$this->_MetaKeyword['value']."'<br/>";
						$strErrorMsg .= "MetaKeyword not updated<br/>";					}

					if($this->_MetaComment['updated'])
					{
						$strSql .= $strJoin." MetaComment = '".$this->_MetaComment['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_MetaComment['oldvalue']."' to '".$this->_MetaComment['value']."'<br/>";
						$strErrorMsg .= "MetaComment not updated<br/>";					}

			$strSql .= "WHERE ID = ". $this->get_ID();
			//Only execute sql if there is something to update.
			if($strJoin == ",")
			{
				//echo nl2br($strSql);
				if(!($DatabaseResult = mysql_query($strSql)))
					return $this->_setFailScreens($strErrorMsg);
				$GLOBALS['arrSuccessMessages'][] = $strSuccessMsg;
			}else
				$GLOBALS['arrSuccessMessages'][] = "No data hasn't changed so no updates made.";
			return(TRUE);
		}
			public function delete_tblSubCategory()
			{
				if($this->get_IDValue() == "")
					return $this->_setFailScreens("Delete aborted no record selected.", true);
				
		
				/* Deleted port forward from agg */
				$strSql =   "DELETE FROM tblSubCategory
		   					  WHERE ID		= ".$this->get_IDValue();
		
				$qryDeletetblSubCategory = new MySqlResults($strSql);
		
				if(!$qryDeletetblSubCategory->result)
					return ($this->_setFailScreens("An error occurred while trying to delete database entry."));
		
		
				$GLOBALS['arrSuccessMessages'][] = " has been removed";
				return true;
			}
		public function insert_tblSubCategory()
		{
			/* Check that all required fields have been set */
			if (!($this->_validateAllFieldsSet()))
			{
				return ($this->_setFailScreens("Fields required to add a new record haven't all been set", true));
			}
			
			$strSql =   "INSERT INTO tblSubCategory
						  (
		 	Category

		, 	SubCategory

		, 	SubCategoryDescription

		, 	DisplayOrder

		, 	UploadedPicture

		, 	MetaTitle

		, 	MetaDescription

		, 	MetaKeyword

		, 	MetaComment
)VALUE(
		 	$this->get_CategoryValue() 
		, 	$this->get_SubCategoryValue() 
		, 	$this->get_SubCategoryDescriptionValue() 
		, 	$this->get_DisplayOrderValue() 
		, 	$this->get_UploadedPictureValue() 
		, 	$this->get_MetaTitleValue() 
		, 	$this->get_MetaDescriptionValue() 
		, 	$this->get_MetaKeywordValue() 
		, 	$this->get_MetaCommentValue() 
			)";
			
			$qryInserttblSubCategory = new MySqlResults($strSql);
		if ($qryInserttblSubCategory->result)
		{
			/*Extra post sql processing  */
		}else
			return $this->_setFailScreens("Unable to add to  tblSubCategory");
			
		return true;
	}
	}

?>